package cn.wolfcode.luowowo.website.util;

import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 */
@ControllerAdvice
public class CommonExceptionHandler {


    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public AjaxResult logicExceptionHandler(Exception e){
        return new AjaxResult(false, e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public AjaxResult runtimeExceptionHandler(Exception e){
        return new AjaxResult(false, "系统繁忙，请稍后重试。");
    }


}
